public class Solution {
  public class TreeNode {
     int val;
     TreeNode left;
     TreeNode right;
     TreeNode() {}
     TreeNode(int val) { this.val = val; }
     TreeNode(int val, TreeNode left, TreeNode right) {
         this.val = val;
         this.left = left;
         this.right = right;
     }
 }
    public int proindex;
    public TreeNode buildTreechild(int[] preorder, int[] inorder,int inbegain,int inend) {
        if(inbegain>inend){
            return null;
        }
        TreeNode root=new TreeNode (preorder[proindex]);
        int rootindex= findval(inorder,inbegain,inend,preorder[proindex]);
        proindex++;
        root.left= buildTreechild( preorder, inorder,inbegain,rootindex-1);
        root.right= buildTreechild( preorder, inorder,rootindex+1,inend);
        return root;
    }
    private int findval(int[] inorder,int inbegain,int inend,int val){
        for(int i=inbegain;i<=inend;i++){
            if(inorder[i]==val){
                return i;
            }
        }
        return -1;
    }
}
